<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>登录</title>
    <link rel="stylesheet" href="/assets/libs/layui/css/layui.css"/>
    <link rel="stylesheet" href="/assets/css/login.css?v=315">
    <link rel="stylesheet" href="/assets/module/admin.css?v=315">
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script>
        if (window != top) {
            top.location.replace(location.href);
        }
    </script>
</head>
<body>
<div class="login-wrapper">

    <div class="login-body">
        <div class="layui-card">
            <div class="layui-card-header">
                <i class="layui-icon layui-icon-engine"></i>&nbsp;&nbsp;用户登录
            </div>
            <form class="layui-card-body layui-form layui-form-pane">
                <div class="layui-form-item">
                    <label class="layui-form-label">账号</label>
                    <div class="layui-input-block">
                        <input type="text" name="username" required  lay-verify="required" placeholder="请输入账号" autocomplete="off" class="layui-input">
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-inline">
                        <input type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-vercode"></i></label>
                    <div class="layui-input-block">
                        <div class="layui-row inline-block">
                            <div class="layui-col-xs7">
                                <input name="verifyCode" type="text" placeholder="验证码" class="layui-input"
                                       autocomplete="off" lay-verType="tips" lay-verify="required" required/>
                            </div>
                            <div class="layui-col-xs5" style="padding-left: 6px;">
                                <img class="login-captcha">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item" style="margin-top: -10px;">
                    <input type="checkbox" name="rememberMe" title="记住我" lay-skin="primary">
                </div>
                <div class="layui-form-item">
                    <button lay-filter="login-submit" class="layui-btn layui-btn-fluid" id="btnLoading" lay-submit>登 录</button>
                </div>

            </form>
        </div>
    </div>

</div>

<!-- js部分 -->
<script type="text/javascript" src="/assets/libs/layui/layui.js"></script>
<script type="text/javascript" src="/assets/js/common.js?v=315"></script>
<script>
    layui.use(['form','notice','admin'], function () {
        var $ = layui.jquery,
         form = layui.form,
         notice = layui.notice,
         admin = layui.admin,
         $view=$(".login-body");

        initCode();

        function initCode(){
          $view.find(".login-captcha").attr("src", "/images/captcha?data=" + new Date().getTime());
        }

        //点击图片更换验证码
        $view.find(".login-captcha").on("click",function () {
            initCode();
        })
        // 表单提交
        form.on('submit(login-submit)', function (obj) {
            admin.btnLoading('#btnLoading');
            $.ajax({
                type: 'post',
                url: "/admin/login",
                dataType: "json",
                data: obj.field,
                success: function (data) {
                    if (data.code === 200) {
                        location.href="/";
                    } else {
                        initCode();
                        admin.btnLoading('#btnLoading',false);
                        notice.msg(data.message,{icon:2,timeout:2000,animateInside:true,audio:'1'});
                    }
                },
            });
            return false;
        });

    });
</script>
</body>
</html>